// components/extend/poster/index.js
var poster = require('./poster')
Component({
  /**
   * 组件的初始数据
   */
  data: {
    posterPath: '',
    flag: false
  },

  /**
   * 组件的方法列表
   */
  methods: {
    genPoster(param) {
      /**
        * img1: '',直播图
        * img2: '',二维码图
        * num: 0,预约数量
        * goods: [],商品列表
       */
      const {img1, img2} = param
      if(!img1 || !img2){
        wx.showToast({
          title: '参数为空',
          icon:'none'
        })
        return
      }
      wx.showLoading({
        title: '海报生成中...',
        mask:true
      })
      this.widget = this.selectComponent('.widget')
      let wxml = poster.getWxml(img1, img2);
      let style = poster.style;
      const p1 = this.widget.renderToCanvas({
        wxml,
        style
      })
      p1.then((res) => {
        const p2 = this.widget.canvasToTempFilePath()
        p2.then(res => {
          this.setData({
            posterPath: res.tempFilePath,
          })
          wx.nextTick(()=>{
            this.setData({
              flag:true
            })
            wx.hideLoading()
          })
        })
      })

    },
    tapCancle(){
      this.setData({
        flag:false
      })
    }

  }
})